<%-- 
    Document   : phoneBookList.jsp
    Created on : 2010. 12. 5, 오후 5:41:31
    Author     : jeffreyha
--%>

<%@page import="net.hekka.canyoutalk.data.vo.PhoneBookVo"%>
<%@page import="net.hekka.canyoutalk.data.vo.list.PhoneBookVoList"%>
<%@page import="net.hekka.canyoutalk.web.vo.PageVo"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Phone Book List</title>
        <link rel="StyleSheet" type="text/css" href="./css/maincss.css" />
    </head>
    
    <%
        HttpSession httpSession = request.getSession();
        PageVo pageVo = (PageVo) request.getAttribute("pageVo");
        PhoneBookVoList phoneBookVoList = (PhoneBookVoList) request.getAttribute("phoneBookVoList");

        int nowPage = (String) request.getAttribute("nowPage") == null ? 0 : Integer.parseInt((String) request.getAttribute("nowPage"));
        int queryCount = (String) request.getAttribute("queryCount") == null ? 0 : Integer.parseInt((String) request.getAttribute("queryCount"));

        int totalPage = (String) request.getAttribute("totalPage") == null ? 0 : Integer.parseInt((String) request.getAttribute("totalPage"));
        int totalCount = (String) request.getAttribute("totalCount") == null ? 0 : Integer.parseInt((String) request.getAttribute("totalCount"));

    %>

    <script language ="javascript">
        function pageChange(pageNumber, endPage) {
            var form = document.phoneBookVoList;
            form.nowPage.value = '<%=nowPage%>';

            if(pageNumber == 'next'){
                if(parseInt(form.nowPage.value) < parseInt(endPage)){
                    form.nowPage.value = parseInt(form.nowPage.value) + 1;
                }else{
                    alert("다음 페이지가 존재하지 않습니다.");
                    return;
                }
            }else if(pageNumber == 'previous'){
                if(parseInt(form.nowPage.value) > 1){
                    form.nowPage.value = parseInt(form.nowPage.value) - 1;
                }else{
                    alert("이전 페이지가 존재하지 않습니다.");
                    return;
                }
            }else{
                form.nowPage.value=pageNumber;
            }

            form.action = "PhoneBookServlet?serviceId=getPhoneBookList&nowPage="+form.nowPage.value+"&totalCount="+form.totalCount.value+"&queryCount=20";
            form.submit();

        }
        
        function setPhoneNumber(phoneNumber, name) {

            var form = document.phoneBookVoList;
            var escapePhoneNumber = encodeURIComponent(phoneNumber);
            var escapeName = encodeURIComponent(name);

            form.target = "main";
            form.action = "PhoneBookServlet?serviceId=getPhoneBookManager&nowPage=1&queryCount=10&phoneNumber="+escapePhoneNumber+"&name="+escapeName;
            form.submit();
        }

        function closeWindow(){
            window.close();
        }
    </script>
            
    <body>
       <div id="wrapper">
           <div id="content" align="center">

 <%
        if (phoneBookVoList != null && phoneBookVoList.size() > 0) {      // 0001
 %>
            <FORM id ="phoneBookVoList" name="phoneBookVoList" method="post" action ="" accept-charset="UTF-8">
                <input type="hidden" name="nowPage" value ='<%=nowPage%>'>
                <input type="hidden" name="queryCount" value ='<%=queryCount%>'>
                <input type="hidden" name="totalPage" value ='<%=totalPage%>'>
                <input type="hidden" name="totalCount" value ='<%=totalCount%>'>

                <table  border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
                    <tr>
                        <td nowrap width="200" 	bgcolor = "#336699" align="center"><font color="white">Phone Number</font></td>
                        <td nowrap width="300" bgcolor = "#336699" align="center"><font color="white"> Name </font></td>
                    </tr>


            <%
                String bgColor = null;
                String packetColor = null;

                for (int i = 0; i < phoneBookVoList.size(); i++) {
                    PhoneBookVo phoneBookVo = phoneBookVoList.get(i);

                    String phoneNumber = phoneBookVo.getNumber();
                    String name = phoneBookVo.getName();

            %>

                    <tr>
                        <td  nowrap  bgcolor="#FFFFFF" align="center"><a href = "javascript:setPhoneNumber('<%=phoneNumber%>','<%=name%>');"><%=phoneNumber%></a> </td>
                        <td nowrap  bgcolor="#FFFFFF" align="center"><b><%=name%></b><br/></td>
                    </tr>

<%
                }
%>
                </table>

                <br/>

                <br/>

                <%
                }
                %>

                <table>
                <tr>
                <td align="center" width="450">&nbsp;
                <IMG SRC="image/btn_notice_prev.png" WIDTH="17" HEIGHT="12" BORDER="0" ALT=""  style="cursor:pointer;" onclick="pageChange('previous', '<%=pageVo.getPageEndNumber()%>');">
                <%
                    for (int i = pageVo.getPageStartNumber(); i <= pageVo.getPageEndNumber(); i++) {
                        if (i == nowPage) {
                %>
                <a href ="javascript:pageChange('<%=i%>','<%=pageVo.getPageEndNumber()%>');"><b><%=i%></b></a>&nbsp;
                <%
                        } else {
                %>
                <a href ="javascript:pageChange('<%=i%>','<%=pageVo.getPageEndNumber()%>');"><%=i%></a>&nbsp;
                <%
                        }
                    }
                %>
                <IMG SRC="image/btn_notice_next.png" WIDTH="17" HEIGHT="12" BORDER="0" ALT="" style="cursor:pointer;" onclick="pageChange('next', '<%=pageVo.getPageEndNumber()%>');">

                </td>
                </tr>
                </table>

</FORM>

            </div>
        </div>
    </body>
</html>
